<?php
error_reporting(E_ALL ^ E_NOTICE);

set_time_limit(0);

$db1=mysql_connect("localhost","root","root"); 
mysql_select_db('devildark',$db1); 
$sql1="SELECT * FROM `report_nojailbreak`"; 
$result1=mysql_query($sql1,$db1); 
$row1=mysql_fetch_array($result1); 
//var_dump($row1['logdate']); 

$db2=mysql_connect('192.168.0.17:5029','root','root'); 
mysql_select_db('devildark',$db2); 
$sql2="SELECT DISTINCT date FROM `devildark`"; 
$result2=mysql_query($sql2,$db2); 
$row2=mysql_fetch_array($result2); 
 
$logdate =  mysql_query("SELECT DISTINCT date FROM `devildark`  ORDER BY date ASC",$db2);

while($everylogdate = mysql_fetch_array($logdate))
{
     //游戏总注册人数
    $loginPersonNum_query = mysql_query("SELECT count(DISTINCT deviceid) FROM devildark where JailBreak = '0'",$db2);

    $loginPersonNum = mysql_fetch_array($loginPersonNum_query);

     //日均活跃人数 
    $activePesonrNum_query1 = mysql_query("SELECT count(DISTINCT deviceid)  FROM devildark where JailBreak = '0'",$db2);
    $activePesonrNum1 = mysql_fetch_array($activePesonrNum_query1);
    $activePesonrNum_query2 = mysql_query("SELECT count( DISTINCT date )FROM devildark",$db2);
    $activePesonrNum2 = mysql_fetch_array($activePesonrNum_query2);
    $activePesonrNum_query = mysql_query("select('$activePesonrNum1[0]')/('$activePesonrNum2[0]')",$db2);
    $activePesonrNum = mysql_fetch_array($activePesonrNum_query);

     //日均活跃人次 activePesonrTime 一个人可能多次
    $activePesonrTime_query1 = mysql_query("SELECT sum(DailyLoginTimes)  FROM devildark where JailBreak = '0'",$db2);
    $activePesonrTime1 = mysql_fetch_array($activePesonrTime_query1);
    $activePesonrTime_query2 = mysql_query("SELECT count( DISTINCT date )FROM devildark",$db2);
    $activePesonrTime2 = mysql_fetch_array($activePesonrTime_query2);
    $activePesonrTime_query = mysql_query("select ('$activePesonrTime1[0]')/('$activePesonrTime2[0]')",$db2);
    $activePesonrTime = mysql_fetch_array($activePesonrTime_query);

    //日均人均打开次数  //DISTINCT deviceid
    $totalDailyLoginTimes_query = mysql_query("SELECT avg(DailyLoginTimes)  FROM devildark where JailBreak = '0'",$db2);
    $totalDailyLoginTimes = mysql_fetch_array($totalDailyLoginTimes_query);

    //日均游戏时间
    $totalDayTotalTime_query = mysql_query("SELECT avg(GamingTime)  FROM devildark where JailBreak = '0'",$db2);
    $totalDayTotalTime = mysql_fetch_array($totalDayTotalTime_query);

     //日均金钱获得
    $totalDayGetMoney_query = mysql_query("SELECT avg(DailyGDGetFromGame) FROM devildark where JailBreak = '0'",$db2);
    $totalDayGetMoney = mysql_fetch_array($totalDayGetMoney_query);

    //日均IAP金钱获得
    $totalDayGetIAPMoney_query1 = mysql_query("SELECT sum(GDGet) FROM devildark  where JailBreak = '0' and date ='$everylogdate[date]'",$db2);
    $totalDayGetIAPMoney1 = mysql_fetch_array($totalDayGetIAPMoney_query1);
    $totalDayGetIAPMoney_query2 = mysql_query("SELECT count(DISTINCT deviceid)  FROM devildark  where date ='$everylogdate[date]' and  JailBreak = '0' and date <> RegisterDate",$db2);
    $totalDayGetIAPMoney2 = mysql_fetch_array($totalDayGetIAPMoney_query2);
    $totalDayGetIAPMoney_query = mysql_query("select ('$totalDayGetIAPMoney1[0]')/('$totalDayGetIAPMoney2[0]')",$db2);
    $totalDayGetIAPMoney = mysql_fetch_array($totalDayGetIAPMoney_query);

    //日均充值 

    $totalDayRecharge_query = mysql_query("SELECT avg(DailyGDGetFromGame) FROM devildark where JailBreak = '0'",$db2);
    $totalDayRecharge = mysql_fetch_array($totalDayRecharge_query);
    
    //日均消费totalDayUsedMoney

    $totalDayUsedMoney_query = mysql_query("SELECT avg(DailyGDLost)  FROM  devildark where JailBreak = '0'",$db2);
    $totalDayUsedMoney = mysql_fetch_array($totalDayUsedMoney_query);
     
    //日均注册人数
    $dayLoginPersonNum_query1 = mysql_query("SELECT count(DISTINCT deviceid) FROM devildark where JailBreak = '0'",$db2);

    $dayLoginPersonNum1 = mysql_fetch_array($dayLoginPersonNum_query1);
    $dayLoginPersonNum_query2 = mysql_query("SELECT count( DISTINCT date )FROM devildark where JailBreak = '0'",$db2);

    $dayLoginPersonNum2 = mysql_fetch_array($dayLoginPersonNum_query2);
    $dayLoginPersonNum_query = mysql_query("select('$dayLoginPersonNum1[0]')/('$dayLoginPersonNum2[0]')",$db2);

    $dayLoginPersonNum = mysql_fetch_array($dayLoginPersonNum_query);

    //totalDayNewusers 每日新注册 DISTINCT
    $totalDayNewusers_query = mysql_query("SELECT count(DISTINCT deviceid)  FROM  devildark  where RegisterDate = '$everylogdate[date]' and  JailBreak = '0'",$db2);
    $totalDayNewusers = mysql_fetch_array($totalDayNewusers_query);

    //DayActivePesonrNum  每日活跃人数  //  日均DailyLoginTimes 活跃人数 今日的
    $dayActivePesonrNum_query = mysql_query("SELECT count(DISTINCT deviceid)  FROM devildark  where date ='$everylogdate[date]' and  JailBreak = '0' and date <> RegisterDate",$db2);
    $dayActivePesonrNum = mysql_fetch_array($dayActivePesonrNum_query);

    //dayActivePesonrTime 每日活跃人次
    $dayActivePesonrTime_query = mysql_query("SELECT sum( DailyLoginTimes ) FROM devildark WHERE JailBreak = '0' and date ='$everylogdate[date]' and date <> RegisterDate ",$db2);
    $dayActivePesonrTime = mysql_fetch_array($dayActivePesonrTime_query);

      //weekOneLandPesonrNum 过去7日内1次登录用户数
     $weekOneLandPesonrNum_query = mysql_query(" SELECT DISTINCT deviceid, date
        FROM devildark
        WHERE JailBreak = '0' and date
        BETWEEN DATE_SUB( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND DATE_SUB( '$everylogdate[date]', INTERVAL 1
        DAY )
        GROUP BY deviceid
        HAVING count( 1 ) >0
        ",$db2);
     $weekOneLandPesonrNum = mysql_num_rows($weekOneLandPesonrNum_query);

     //weekActivePesonrNum   过去7日内2次登录用户数 每周活跃人数  SELECT * FROM devildark   where DATE_SUB( date, INTERVAL 7 DAY ) <= date( '$everylogdate[date]' )
    $weekActivePesonrNum_query = mysql_query("  SELECT DISTINCT deviceid, date
        FROM devildark
        WHERE JailBreak = '0' and date
        BETWEEN DATE_SUB( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND DATE_SUB( '$everylogdate[date]', INTERVAL 1
        DAY )
        GROUP BY deviceid
        HAVING count( 1 ) >1
        ",$db2);
    //$weekActivePesonrNum_query = mysql_query("SELECT count(DISTINCT deviceid)  FROM  devildark  where date_add(date,interval 2 day)   and DATE_SUB( date, INTERVAL 7 DAY ) <= date( '$everylogdate[date]' )  and  JailBreak = '0'",$db2);
    $weekActivePesonrNum = mysql_num_rows($weekActivePesonrNum_query);

    //weekLoyalPesonrNum  过去7日内3次登录用户数 每周忠诚用户人数
    $weekLoyalPesonrNum_query = mysql_query("SELECT DISTINCT deviceid, date
        FROM devildark
        WHERE JailBreak = '0' and  date
        BETWEEN DATE_SUB( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND DATE_SUB( '$everylogdate[date]', INTERVAL 1
        DAY )
        GROUP BY deviceid
        HAVING count( 1 ) >2
       ",$db2);
   $weekLoyalPesonrNum = mysql_num_rows($weekLoyalPesonrNum_query);


    //weekCorePesonrNum  过去7日内4次登录用户数 每周核心用户人数
    $weekCorePesonrNum_query = mysql_query("SELECT DISTINCT deviceid, date
        FROM devildark
        WHERE JailBreak = '0' and  date
        BETWEEN DATE_SUB( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND DATE_SUB( '$everylogdate[date]', INTERVAL 1
        DAY )
        GROUP BY deviceid
        HAVING count( 1 ) >3
        ",$db2);
    $weekCorePesonrNum = mysql_num_rows($weekCorePesonrNum_query);

    // 挂网等雇佣用户数 //字段缺失
    //$hirePesonrNum_query = mysql_query("SELECT count(DISTINCT deviceid)  FROM  devildark  where  date ='$everylogdate[date]'  and  JailBreak = '0'",$db2);
    //$hirePesonrNum = mysql_fetch_array($hirePesonrNum_query);

    //  今日均人均游戏时间
    $dayTotalTime_query1 = mysql_query("SELECT sum(DailyGamingTime)  FROM devildark  where  date ='$everylogdate[date]' and  JailBreak = '0'",$db2);
    $dayTotalTime1 = mysql_fetch_array($dayTotalTime_query1);
    $dayTotalTime_query2 = mysql_query("SELECT count(DISTINCT deviceid)  FROM devildark  where date ='$everylogdate[date]' and  JailBreak = '0' and date <> RegisterDate",$db2);
    $dayTotalTime2 = mysql_fetch_array($dayTotalTime_query2);
    $dayTotalTime_query = mysql_query("select ('$dayTotalTime1[0]')/('$dayTotalTime2[0]')",$db2);
    $dayTotalTime = mysql_fetch_array($dayTotalTime_query);

    //  今日均消费金钱 DayUsedMoney 
    $dayUsedMoney_query1 = mysql_query("SELECT sum(DailyGDLost)  FROM  devildark   where date ='$everylogdate[date]' and  JailBreak = '0'",$db2);
    $dayUsedMoney1 = mysql_fetch_array($dayUsedMoney_query1);
    $dayUsedMoney_query = mysql_query("select ('$dayUsedMoney1[0]')/('$dayActivePesonrNum[0]')",$db2);
    $dayUsedMoney = mysql_fetch_array($dayUsedMoney_query);

        //weekPayPesonrNum 周付费用户数 SELECT count( DISTINCT deviceid )   
    $weekPayPesonrNum_query = mysql_query("SELECT count(distinct deviceid)  FROM  devildark  where DailyTCGet >0 and date BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
DAY ) AND '$everylogdate[date]' and  jailbreak = '0'",$db2);
    $weekPayPesonrNum = mysql_fetch_array($weekPayPesonrNum_query);
    //dayIAPGetMoney  今日人均 IAP 获得金钱
    $dayIAPGetMoney_query1 = mysql_query("SELECT sum(DailyTCGet)  FROM  devildark  where  date ='$everylogdate[date]' and  JailBreak = '0'",$db2);
    $dayIAPGetMoney1 = mysql_fetch_array($dayIAPGetMoney_query1);
    $dayIAPGetMoney_query2 = mysql_query("SELECT count(deviceid)  FROM  devildark  where  date ='$everylogdate[date]' and  JailBreak = '0' and DailyLoginTimes > '2'",$db2);
    $dayIAPGetMoney2 = mysql_fetch_array($dayIAPGetMoney_query2);

    $dayIAPGetMoney_query = mysql_query("select ('$dayIAPGetMoney1[0]')/('$dayIAPGetMoney2[0]')",$db2);
    $dayIAPGetMoney = mysql_fetch_array($dayIAPGetMoney_query);
    //avgDayMoney  今日人均获得金钱
    $avgDayMoney_query1 = mysql_query("SELECT sum(DailyGDGetFromGame)  FROM  devildark  where  date ='$everylogdate[date]' and  JailBreak = '0')",$db2);
    $avgDayMoney1 = mysql_fetch_array($avgDayMoney_query1);
    $avgDayMoney_query2 = mysql_query("SELECT count(deviceid)  FROM  devildark  where  date ='$everylogdate[date]' and  JailBreak = '0'",$db2);
    $avgDayMoney2 = mysql_fetch_array($avgDayMoney_query2);
    $avgDayMoney_query = mysql_query("select ('$avgDayMoney1[0]')/('$avgDayMoney2[0]')",$db2);
    $avgDayMoney = mysql_fetch_array($avgDayMoney_query);
    
    //dayNowMoney  今日人均现有金钱
    $dayNowMoney_query1 = mysql_query("SELECT sum(CurrentGD)  FROM  devildark  where  date ='$everylogdate[date]' and  JailBreak = '0'",$db2);
    $dayNowMoney1 = mysql_fetch_array($dayNowMoney_query1);
    $dayNowMoney_query2 = mysql_query("SELECT count(deviceid)  FROM  devildark  where  date ='$everylogdate[date]' and  JailBreak = '0'",$db2);
    $dayNowMoney2= mysql_fetch_array($dayNowMoney_query2);
    $dayNowMoney_query = mysql_query("select ('$dayNowMoney1[0]')/('$dayNowMoney2[0]')",$db2);
    $dayNowMoney = mysql_fetch_array($dayNowMoney_query);
    //dayRechargeNum  今日人均充值笔数
    $dayRechargeNum_query1 = mysql_query("SELECT sum(DailyTCTimes)  FROM  devildark  where  date ='$everylogdate[date]' and JailBreak = '0'",$db2);
    $dayRechargeNum1 = mysql_fetch_array($dayRechargeNum_query1);
    $dayRechargeNum_query2 = mysql_query("SELECT count(deviceid)  FROM  devildark  where  date ='$everylogdate[date]' and JailBreak = '0' and DailyTCGet >0",$db2);
    $dayRechargeNum2 = mysql_fetch_array($dayRechargeNum_query2);
    $dayRechargeNum_query = mysql_query("select ('$dayRechargeNum1[0]')/('$dayRechargeNum2[0]')",$db2);
    $dayRechargeNum = mysql_fetch_array($dayRechargeNum_query);
  
    //weekPayARPU 周付费用户ARPU值 =周付费总额/周付费人数
    $weekPayARPU_query1 = mysql_query("SELECT sum( DailyTCGet )
        FROM devildark
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND jailbreak = '0'",$db2);

    $weekPayARPU1 = mysql_fetch_array($weekPayARPU_query1); 
    $weekPayARPU_query = mysql_query("SELECT ('$weekPayARPU1[0]') / ('$weekPayPesonrNum[0]' )",$db2);

    $weekPayARPU = mysql_fetch_array($weekPayARPU_query); 
     
    //weekActiveARPU 周活跃用户ARPU值
    $weekActiveARPU_query1 = mysql_query("SELECT sum( DailyTCGet )
        FROM devildark
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND jailbreak = '0'",$db2);
    $weekActiveARPU1 = mysql_fetch_array($weekActiveARPU_query1);
    $weekActiveARPU_query = mysql_query("SELECT ('$weekActiveARPU1[0]') / ('$weekActivePesonrNum') ",$db2);
    $weekActiveARPU = mysql_fetch_array($weekActiveARPU_query);
       //weekLogARPU 周登陆用户ARPU值  = 周付费用户/周登陆人数(活跃用户+新用户) 
    $weekLogARPU_query1 = mysql_query("SELECT sum( DailyTCGet )
        FROM devildark
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND jailbreak = '0' ",$db2);
    $weekLogARPU1 = mysql_fetch_array($weekLogARPU_query1);
    $weekLogARPU_query2 = mysql_query("SELECT count( DISTINCT deviceid )
        FROM devildark
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND jailbreak = '0'  ",$db2);
    $weekLogARPU2 = mysql_fetch_array($weekLogARPU_query2); 
    $weekLogARPU_query = mysql_query("SELECT ('$weekLogARPU1[0]') / ('$weekLogARPU2[0]') ",$db2);
      $weekLogARPU = mysql_fetch_array($weekLogARPU_query);
      //weekWastageRate  周活跃用户流失率 上周活跃用户在本周没有登陆过游戏的用户数，除以上周的活跃人数。
      $weekWastageRate_query = mysql_query("SELECT concat(round((

        SELECT (

        SELECT count( a.deviceid )
        FROM weekActive a
        WHERE a.date = date_sub('$everylogdate[date]',interval 7 day)  
        AND a.deviceid NOT
        IN (

        SELECT DISTINCT deviceid
        FROM devildark
        WHERE jailbreak = '0'
        AND date
        BETWEEN DATE_SUB('$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) / (
        SELECT count( 1 )
        FROM weekActive
        WHERE date = date_sub('$everylogdate[date]',interval 7 day))
        ) *100,2), '%'
        ) ",$db1);
     $weekWastageRate = mysql_fetch_array($weekWastageRate_query); 
      //weekPayRate  周活跃用户付费率 周付费用户数除以周活跃人数
    //$weekPayRate_query = mysql_query("select '$weekPayPesonrNum[0]'/'$weekActivePesonrNum[0]'",$db2);
    $weekPayRate_query = mysql_query("SELECT concat(round( '$weekPayPesonrNum[0]'/  '$weekActivePesonrNum' *100,2), '%' ) ",$db2);
    $weekPayRate = mysql_fetch_array($weekPayRate_query);
    //weekLogPayRate周登陆用户付费率 周付费用户数除以周登陆人数
    $weekLogPayRate_query = mysql_query("SELECT concat(round( '$weekPayPesonrNum[0]'/  '$weekOneLandPesonrNum' *100,2), '%' ) ",$db2);
    $weekLogPayRate = mysql_fetch_array($weekLogPayRate_query);
       //weekPayWastageRate  周付费用户流失率 上周有付费行为而本周7天未登陆的用户数除以上周的付费用户数  
    $weekPayWastageRate_query = mysql_query("SELECT concat(round( (

        SELECT (

        SELECT count( a.deviceid )
        FROM weekPay a
        WHERE a.date = date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND a.deviceid NOT
        IN (

        SELECT DISTINCT deviceid
        FROM devildark
        WHERE jailbreak = '0'
        AND date
        BETWEEN DATE_SUB( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) / (
        SELECT count( 1 )
        FROM weekPay
        WHERE date =  date_sub('$everylogdate[date]',interval 7 day) )
        ) *100,2), '%'
        )  ",$db1);
     $weekPayWastageRate = mysql_fetch_array($weekPayWastageRate_query);
     //周付费用户人均充值笔数 //
     $weekPayPesonrTime_query = mysql_query("SELECT '$WeekPayRechargeNum[0]'/'$weekPayPesonrNum[0]'",$db2);
     $weekPayPesonrTime = mysql_fetch_array($weekPayPesonrTime_query);

    //今日TC兑换次数 
    $DailyTCTimes_query = mysql_query("SELECT sum(DailyGDExchangeTimes)  FROM  devildark  where date = '$everylogdate[date]'  and  JailBreak = '0'",$db2);
    $DailyTCTimes = mysql_fetch_array($DailyTCTimes_query);

    //今日TC兑换金钱消耗量
    $DailyTCLost_query = mysql_query("SELECT sum(DailyTCLost)  FROM  devildark  where date = '$everylogdate[date]'  and  JailBreak = '0'",$db2);
    $DailyTCLost = mysql_fetch_array($DailyTCLost_query);
/*
    //最后退出 10界面 人数统计 Lastloginscreen10Num
    $Lastloginscreen10Num_query = mysql_query("SELECT count(distinct deviceid) FROM devildark where JailBreak = '0' and UILastId = 10  and date ='$everylogdate[date]'",$db2);
    $Lastloginscreen10Num = mysql_fetch_array($Lastloginscreen10Num_query);

        //最后退出 21界面 人数统计 Lastloginscreen10Num
    $Lastloginscreen21Num_query = mysql_query("SELECT count(distinct deviceid) FROM devildark where JailBreak = '0' and UILastId = 21  and date ='$everylogdate[date]'",$db2);
    $Lastloginscreen21Num = mysql_fetch_array($Lastloginscreen21Num_query);

        //最后退出 22界面 人数统计 Lastloginscreen10Num
    $Lastloginscreen22Num_query = mysql_query("SELECT count(distinct deviceid) FROM devildark where JailBreak = '0' and UILastId = 22  and date ='$everylogdate[date]'",$db2);
    $Lastloginscreen22Num = mysql_fetch_array($Lastloginscreen22Num_query);
        //最后退出 23界面 人数统计 Lastloginscreen10Num
    $Lastloginscreen23Num_query = mysql_query("SELECT count(distinct deviceid) FROM devildark where JailBreak = '0' and UILastId = 23  and date ='$everylogdate[date]'",$db2);
    $Lastloginscreen23Num = mysql_fetch_array($Lastloginscreen23Num_query);
        //最后退出 24界面 人数统计 Lastloginscreen10Num
    $Lastloginscreen24m_query = mysql_query("SELECT count(distinct deviceid) FROM devildark where JailBreak = '0' and UILastId = 24  and date ='$everylogdate[date]'",$db2);
    $Lastloginscreen24Num = mysql_fetch_array($Lastloginscreen24m_query);
        //最后退出 31界面 人数统计 Lastloginscreen10Num
    $Lastloginscreen31Num_query = mysql_query("SELECT count(distinct deviceid) FROM devildark where JailBreak = '0' and UILastId = 31  and date ='$everylogdate[date]'",$db2);
    $Lastloginscreen31Num = mysql_fetch_array($Lastloginscreen31Num_query);
        //最后退出 41界面 人数统计 Lastloginscreen10Num
    $Lastloginscreen41Num_query = mysql_query("SELECT count(distinct deviceid) FROM devildark where JailBreak = '0' and UILastId = 41  and date ='$everylogdate[date]'",$db2);
    $Lastloginscreen41Num = mysql_fetch_array($Lastloginscreen41Num_query);
        //最后退出 42界面 人数统计 Lastloginscreen10Num
    $Lastloginscreen42Num_query = mysql_query("SELECT count(distinct deviceid) FROM devildark where JailBreak = '0' and UILastId = 42  and date ='$everylogdate[date]'",$db2);
    $Lastloginscreen42Num = mysql_fetch_array($Lastloginscreen42Num_query);
        //最后退出 50界面 人数统计 Lastloginscreen10Num
    $Lastloginscreen50Num_query = mysql_query("SELECT count(distinct deviceid) FROM devildark where JailBreak = '0' and UILastId = 50  and date ='$everylogdate[date]'",$db2);
    $Lastloginscreen50Num = mysql_fetch_array($Lastloginscreen50Num_query);
        //最后退出 60界面 人数统计 Lastloginscreen10Num
    $Lastloginscreen60Num_query = mysql_query("SELECT count(distinct deviceid) FROM devildark where JailBreak = '0' and UILastId = 60  and date ='$everylogdate[date]'",$db2);
    $Lastloginscreen60Num = mysql_fetch_array($Lastloginscreen60Num_query);
        //最后退出 71界面 人数统计 Lastloginscreen10Num
    $Lastloginscreen71Num_query = mysql_query("SELECT count(distinct deviceid) FROM devildark where JailBreak = '0' and UILastId = 71  and date ='$everylogdate[date]'",$db2);
    $Lastloginscreen71Num = mysql_fetch_array($Lastloginscreen71Num_query);
        //最后退出 72界面 人数统计 Lastloginscreen10Num
    $Lastloginscreen72Num_query = mysql_query("SELECT count(distinct deviceid) FROM devildark where JailBreak = '0' and UILastId = 72  and date ='$everylogdate[date]'",$db2);
    $Lastloginscreen72Num = mysql_fetch_array($Lastloginscreen72Num_query);
        //最后退出 73界面 人数统计 Lastloginscreen10Num
    $Lastloginscreen73Num_query = mysql_query("SELECT count(distinct deviceid) FROM devildark where JailBreak = '0' and UILastId = 73  and date ='$everylogdate[date]'",$db2);
    $Lastloginscreen73Num = mysql_fetch_array($Lastloginscreen73Num_query);
        //最后退出 80界面 人数统计 Lastloginscreen10Num
    $Lastloginscreen80Num_query = mysql_query("SELECT count(distinct deviceid) FROM devildark where JailBreak = '0' and UILastId = 80  and date ='$everylogdate[date]'",$db2);
    $Lastloginscreen80Num = mysql_fetch_array($Lastloginscreen80Num_query);
*/  

     // p1等级分布 (1,2,....)
    $date = array('1' => array($p1date1Count, $date1), array($p1date2Count, $date2), array($p1date3Count, $date3), array($p1date4Count, $date4), array($p1date5Count, $date5), array($p1date6Count, $date6), array($p1date7Count, $date7), array($p1date8Count, $date8), array($p1date9Count, $date9), array($p1date10Count, $date10), array($p1date11Count, $date11), array($p1date12Count, $date12), array($p1date13Count, $date13), array($p1date14Count, $date14), array($p1date15Count, $date15), array($p1date16Count, $date16), array($p1date17Count, $date17), array($p1date18Count, $date18), array($p1date19Count, $date19), array($p1date20Count, $date20), array($p1date21Count, $date21));
    // $date1[] = 
    /*$date1_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel =1
        AND JailBreak = '0' ) / (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND JailBreak = '0' )
        ) *100, '%')
        ",$db2);
            $date1_a = mysql_fetch_array($date1_query);*/
            $date1_a = 0;
            $date1 = $date1_a[0];
            $p1date1Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM devildark
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel =1
        AND JailBreak = '0'
        ",$db2);
    $p1date1Count_a = mysql_fetch_array($p1date1Count_query);
    $p1date1Count = $p1date1Count_a[0];
    /*$date2_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel =2
        AND JailBreak = '0' ) / (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND JailBreak = '0' )
        ) *100, '%')
        ",$db2);
    $date2_a = mysql_fetch_array($date2_query);*/
    $date2_a =0;
    $date2 = $date2_a[0];
    $p1date2Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM devildark
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel =2
        AND JailBreak = '0'",$db2);
    $p1date2Count_a = mysql_fetch_array($p1date2Count_query);
    $p1date2Count = $p1date2Count_a[0];
    /*$date3_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel =3
        AND JailBreak = '0' ) / (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND JailBreak = '0' )
        ) *100, '%')
        ",$db2);
    $date3_a = mysql_fetch_array($date3_query);*/
    $date3_a = 0;
    $date3 = $date3_a[0];
    $p1date3Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM devildark
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel =3
        AND JailBreak = '0'",$db2);
    $p1date3Count_a = mysql_fetch_array($p1date3Count_query);
    $p1date3Count = $p1date3Count_a[0];
    /*$date4_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel =4
        AND JailBreak = '0' ) / (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND JailBreak = '0' )
        ) *100, '%')
        ",$db2);
    $date4_a = mysql_fetch_array($date4_query);*/
    $date4_a = 0;
    $date4 = $date4_a[0];
    $p1date4Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM devildark
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel =4
        AND JailBreak = '0'",$db2);
    $p1date4Count_a = mysql_fetch_array($p1date4Count_query);
    $p1date4Count = $p1date4Count_a[0];
    /*$date5_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel =5
        AND JailBreak = '0' ) / (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND JailBreak = '0' )
        ) *100, '%')
        ",$db2);
    $date5_a = mysql_fetch_array($date5_query);*/
    $date5_a =0;
    $date5 = $date5_a[0];
    $p1date5Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM devildark
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel =5
        AND JailBreak = '0'",$db2);
    $p1date5Count_a = mysql_fetch_array($p1date5Count_query);
    $p1date5Count = $p1date5Count_a[0];
    /*$date6_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel =6
        AND JailBreak = '0' ) / (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND JailBreak = '0' )
        ) *100, '%')
        ",$db2);
    $date6_a = mysql_fetch_array($date6_query);*/
    $date6_a = 0;
    $date6 = $date6_a[0];
    $p1date6Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM devildark
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel =6
        AND JailBreak = '0'",$db2);
    $p1date6Count_a = mysql_fetch_array($p1date6Count_query);
    $p1date6Count = $p1date6Count_a[0];
    /*$date7_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel =7
        AND JailBreak = '0' ) / (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND JailBreak = '0' )
        ) *100, '%')
        ",$db2);
    $date7_a = mysql_fetch_array($date7_query);*/
    $date7_a =0;
    $date7 = $date7_a[0];
    $p1date7Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM devildark
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel =7
        AND JailBreak = '0'",$db2);
    $p1date7Count_a = mysql_fetch_array($p1date7Count_query);
    $p1date7Count = $p1date7Count_a[0];
    /*$date8_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel =8
        AND JailBreak = '0' ) / (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND JailBreak = '0' )
        ) *100, '%')
        ",$db2);
    $date8_a = mysql_fetch_array($date8_query);*/
     $date8_a =0;
    $date8 = $date8_a[0];
    $p1date8Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM devildark
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel =8
        AND JailBreak = '0'",$db2);
    $p1date8Count_a = mysql_fetch_array($p1date8Count_query);
    $p1date8Count = $p1date8Count_a[0];
    /*$date9_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel =9
        AND JailBreak = '0' ) / (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND JailBreak = '0' )
        ) *100, '%')
        ",$db2);
    $date9_a = mysql_fetch_array($date9_query);*/
    $date9_a = 0;
    $date9 = $date9_a[0];
    $p1date9Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM devildark
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel =9
        AND JailBreak = '0'",$db2);
    $p1date9Count_a = mysql_fetch_array($p1date9Count_query);
    $p1date9Count = $p1date9Count_a[0];
    /*$date10_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel =10
        AND JailBreak = '0' ) / (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND JailBreak = '0' )
        ) *100, '%')
        ",$db2);
    $date10_a = mysql_fetch_array($date10_query);*/
    $date10_a = 0;
    $date10 = $date10_a[0];
    $p1date10Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM devildark
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel =10
        AND JailBreak = '0'",$db2);
    $p1date10Count_a = mysql_fetch_array($p1date10Count_query);
    $p1date10Count = $p1date10Count_a[0];
    /*$date11_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel between 11 and 15
        AND JailBreak = '0' ) / (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND JailBreak = '0' )
        ) *100, '%')
        ",$db2);
    $date11_a = mysql_fetch_array($date11_query);*/
    $date11_a =0;
    $date11 = $date11_a[0];
    $p1date11Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM devildark
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel between 11 and 15
        AND JailBreak = '0'",$db2);
    $p1date11Count_a = mysql_fetch_array($p1date11Count_query);
    $p1date11Count = $p1date11Count_a[0];
    /*$date12_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel between 16 and 20
        AND JailBreak = '0' ) / (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND JailBreak = '0' )
        ) *100, '%')",$db2);
    $date12_a = mysql_fetch_array($date12_query);*/
    $date12_a =0;
    $date12 = $date12_a[0];
    $p1date12Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM devildark
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel between 16 and 20
        AND JailBreak = '0'",$db2);
    $p1date12Count_a = mysql_fetch_array($p1date12Count_query);
    $p1date12Count = $p1date12Count_a[0];
    /*$date13_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel between 21 and 25
        AND JailBreak = '0' ) / (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND JailBreak = '0' )
        ) *100, '%')",$db2);
    $date13_a = mysql_fetch_array($date13_query);*/
    $date13_a = 0;
    $date13 = $date13_a[0];
    $p1date13Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM devildark
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel between 21 and 25
        AND JailBreak = '0'",$db2);
    $p1date13Count_a = mysql_fetch_array($p1date13Count_query);
    $p1date13Count = $p1date13Count_a[0];
    /*$date14_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel between 26 and 30
        AND JailBreak = '0' ) / (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND JailBreak = '0' )
        ) *100, '%')",$db2);
    $date14_a = mysql_fetch_array($date14_query);*/
    $date14_a = 0;
    $date14 = $date14_a[0];
    $p1date14Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM devildark
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel between 26 and 30
        AND JailBreak = '0'",$db2);
    $p1date14Count_a = mysql_fetch_array($p1date14Count_query);
    $p1date14Count = $p1date14Count_a[0];
    /*$date15_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel between 31 and 40
        AND JailBreak = '0' ) / (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND JailBreak = '0' )
        ) *100, '%')",$db2);
    $date15_a = mysql_fetch_array($date15_query);*/
    $date15_a =0;
    $date15 = $date15_a[0];
    $p1date15Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM devildark
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel between 31 and 40
        AND JailBreak = '0'",$db2);
    $p1date15Count_a = mysql_fetch_array($p1date15Count_query);
    $p1date15Count = $p1date15Count_a[0];
    /*$date16_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel between 41 and 50
        AND JailBreak = '0' ) / (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND JailBreak = '0' )
        ) *100, '%')",$db2);
    $date16_a = mysql_fetch_array($date16_query);*/
    $date16_a =0;
    $date16 = $date16_a[0];
    $p1date16Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM devildark
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel between 41 and 50
        AND JailBreak = '0'",$db2);
    $p1date16Count_a = mysql_fetch_array($p1date16Count_query);
    $p1date16Count = $p1date16Count_a[0];
    /*$date17_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel between 51 and 60
        AND JailBreak = '0' ) / (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND JailBreak = '0' )
        ) *100, '%')",$db2);
    $date17_a = mysql_fetch_array($date17_query);*/
    $date17_a =0;
    $date17 = $date17_a[0];
    $p1date17Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM devildark
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel between 51 and 60
        AND JailBreak = '0'",$db2);
    $p1date17Count_a = mysql_fetch_array($p1date17Count_query);
    $p1date17Count = $p1date17Count_a[0];
    /*$date18_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel between 61 and 70
        AND JailBreak = '0' ) / (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND JailBreak = '0' )
        ) *100, '%')",$db2);
    $date18_a = mysql_fetch_array($date18_query);*/
    $date18_a = 0;
    $date18 = $date18_a[0];
    $p1date18Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM devildark
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel between 61 and 70
        AND JailBreak = '0'",$db2);
    $p1date18Count_a = mysql_fetch_array($p1date18Count_query);
    $p1date18Count = $p1date18Count_a[0];
    /*$date19_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel between 71 and 80
        AND JailBreak = '0' ) / (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND JailBreak = '0' )
        ) *100, '%')",$db2);
    $date19_a = mysql_fetch_array($date19_query);*/
    $date19_a =0;
    $date19 = $date19_a[0];
    $p1date19Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM devildark
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel between 71 and 80
        AND JailBreak = '0'",$db2);
    $p1date19Count_a = mysql_fetch_array($p1date19Count_query);
    $p1date19Count = $p1date19Count_a[0];
    /*$date20_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel between 81 and 90
        AND JailBreak = '0' ) / (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND JailBreak = '0' )
        ) *100, '%')",$db2);
    $date20_a = mysql_fetch_array($date20_query);*/
    $date20_a =0;
    $date20 = $date20_a[0];
    $p1date20Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM devildark
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel between 81 and 90
        AND JailBreak = '0'",$db2);
    $p1date20Count_a = mysql_fetch_array($p1date20Count_query);
    $p1date20Count = $p1date20Count_a[0];
    /*$date21_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel between 91 and 100
        AND JailBreak = '0' ) / (
        SELECT count( DISTINCT deviceid )
        FROM devildark 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND JailBreak = '0' )
        ) *100, '%')",$db2);
    $date21_a = mysql_fetch_array($date21_query);*/
    $date21_a =0;
    $date21 = $date21_a[0];
    $p1date21Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM devildark
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND CurrentPlayerLevel between 91 and 100
        AND JailBreak = '0'",$db2);
    $p1date21Count_a = mysql_fetch_array($p1date21Count_query);
    $p1date21Count = $p1date21Count_a[0];
    $CurrentPlayerLevel = array(json_encode($date));//等级分布

         //WeekNewPayPesonrNum 过去7日内新增注册用户数
    $WeekNewPayPesonrNum_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM devildark
        WHERE RegisterDate
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND JailBreak = '0'",$db2);
    $WeekNewPayPesonrNum = mysql_fetch_array($WeekNewPayPesonrNum_query);
     //MonthLandTwicePesonrNum 过去30日内2次登录用户数
    $MonthLandTwicePesonrNum_query = mysql_query("SELECT DISTINCT deviceid, date
        FROM devildark
        WHERE JailBreak = '0'
        AND date
        BETWEEN DATE_SUB( '$everylogdate[date]', INTERVAL 30
        DAY )
        AND DATE_SUB( '$everylogdate[date]', INTERVAL 1
        DAY )
        GROUP BY deviceid
        HAVING count( 1 ) >1 ",$db2);
    $MonthLandTwicePesonrNum = mysql_num_rows($MonthLandTwicePesonrNum_query);

          //WeekPayRechargeNum 周付费用户充值笔数
    $WeekPayRechargeNum_query = mysql_query("SELECT sum(DailyTCTimes )
        FROM devildark
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND jailbreak = '0'
        ",$db2);
    $WeekPayRechargeNum = mysql_fetch_array($WeekPayRechargeNum_query);
  
      //newPayPesonrNum  新增付费人数
    $newPayPesonrNum_query = mysql_query("SELECT count(DISTINCT deviceid)  FROM  devildark a where DailyTCGet >0 and  date ='$everylogdate[date]' and  jailbreak = '0' and  not exists (SELECT DISTINCT deviceid  FROM  devildark  where DailyTCGet >0 and  date < '$everylogdate[date]' and  jailbreak = '0' and a.deviceid = deviceid)",$db2);
    $newPayPesonrNum = mysql_fetch_array($newPayPesonrNum_query);
        //今日付费次数 paytimes
    $paytimes_query = mysql_query("SELECT sum(DailyTCTimes)  FROM  devildark  where  date ='$everylogdate[date]' and  jailbreak = '0'",$db2);
    $paytimes = mysql_fetch_array($paytimes_query);
    //今日付费用户数 PayPesonrNum
    $PayPesonrNum_query = mysql_query("SELECT count(deviceid)  FROM  devildark  where  date ='$everylogdate[date]' and DailyTCGet >0 and  jailbreak = '0'",$db2);
    $PayPesonrNum = mysql_fetch_array($PayPesonrNum_query);
   
 $sql="REPLACE INTO report_nojailbreak (logdate,loginPersonNum,activePesonrNum,activePesonrTime,totalDayTotalTime,
                                        totalDayGetMoney,totalDayRecharge,totalDayUsedMoney,dayLoginPersonNum,
                                        totalDayNewusers,dayActivePesonrNum,dayActivePesonrTime,weekActivePesonrNum,weekLoyalPesonrNum,weekCorePesonrNum,
                                        dayTotalTime,dayUsedMoney,weekPayPesonrNum,dayIAPGetMoney,
                                        avgDayMoney,dayNowMoney,
                                        
                                        weekPayARPU,weekActiveARPU,weekLogARPU,weekWastageRate,weekPayRate,weekLogPayRate,weekPayWastageRate,
                                        DailyTCTimes,DailyTCLost,totalDayGetIAPMoney,playerLevel,totalDayPlayTime,
                                        weekOneLandPesonrNum,WeekNewPayPesonrNum,MonthLandTwicePesonrNum,newPayPesonrNum,paytimes,PayPesonrNum,
                                        dayRechargeNum,WeekPayRechargeNum,weekPayPesonrTime) 
                  VALUES('$everylogdate[date]','$loginPersonNum[0]','$activePesonrNum[0]','$activePesonrTime[0]','$totalDayTotalTime[0]',
                         '$totalDayGetMoney[0]','$totalDayRecharge[0]','$totalDayUsedMoney[0]','$dayLoginPersonNum[0]',
                         '$totalDayNewusers[0]','$dayActivePesonrNum[0]','$dayActivePesonrTime[0]','$weekActivePesonrNum','$weekLoyalPesonrNum','$weekCorePesonrNum',
                          '$dayTotalTime[0]','$dayUsedMoney[0]','$weekPayPesonrNum[0]','$dayIAPGetMoney[0]',
                          '$avgDayMoney[0]','$dayNowMoney[0]',
                        
                          '$weekPayARPU[0]','$weekActiveARPU[0]','$weekLogARPU[0]','$weekWastageRate[0]','$weekPayRate[0]','$weekLogPayRate[0]','$weekPayWastageRate[0]',
                          '$DailyTCTimes[0]','$DailyTCLost[0]','$totalDayGetIAPMoney[0]','$CurrentPlayerLevel[0]','$totalDailyLoginTimes[0]',
                          '$weekOneLandPesonrNum','$WeekNewPayPesonrNum[0]','$MonthLandTwicePesonrNum','$newPayPesonrNum[0]','$paytimes[0]','$PayPesonrNum[0]',
                          '$dayRechargeNum[0]','$WeekPayRechargeNum[0]','$weekPayPesonrTime[0]')";
$query= @mysql_query($sql,$db1) or die(mysql_error());  

}
?>
